/**
 * 
 */
package com.chee.plant.encrypt;

import java.io.IOException;

import sun.misc.BASE64Encoder;
import sun.misc.BASE64Decoder;

/**
 *
 */
public class Base64 {
	private BASE64Encoder _encoder;
	private BASE64Decoder _decoder;
	public Base64(){
		this._encoder = new BASE64Encoder();
		this._decoder = new BASE64Decoder();
	}
	public String encode(String rawString){
		if(rawString == null || rawString == "") return "";
		return this._encoder.encode(rawString.getBytes());
	}
	public String decode(String cryptString){
		byte[] bytes;
		try {
			bytes = this._decoder.decodeBuffer(cryptString);
			String decoded = new String(bytes);
			return decoded;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return "";
		}
	}
	public static void main(String[] args){
		Base64 b = new Base64();
		String raw = "testdbtestdbtestdb";
		System.out.println(b.encode(raw));
	}
}
